import { useTable, LIST_TYPE } from '@crud/index';
import { formatParamsSelectVal, toolOptions2Map } from '@/utils';
import { getList } from '@/api/crm-content/notice';

// 公告类型
export const typeOptions: any = [
  { label: '公告', value: 1 },
  { label: '行业报告', value: 2 }
];

// 发送对象
export const sendObjectOptions: any = [
  { label: '全部', value: 0 },
  { label: '大赢加', value: 1 },
  { label: '考古加', value: 2 }
];
// 类型
export const typeMap: any = toolOptions2Map(typeOptions);

// 发送对象
export const sendObjectMap: any = toolOptions2Map(sendObjectOptions);

// 表格
export const useTableList = (options: any = {}) => {
  const columns = [
    { label: '消息ID', prop: 'id', width: 120, fixed: 'left' },
    { label: '消息标题', prop: 'title', minWidth: 200, ellipsis: true, showOverflowTooltip: true },
    { label: '消息类型', prop: 'type', minWidth: 120, render: (s: any) => typeMap[s.row.type] },
    { label: '发送对象', prop: 'send_object', minWidth: 120, render: (s: any) => sendObjectMap[s.row.send_object] },
    { label: '浏览数', prop: 'view_count', minWidth: 120, render: (s: any) => s.row.view_count || '-' },
    { label: '操作人', prop: 'user_name', minWidth: 120, render: (s: any) => s.row.user_name || '-' },
    { label: '发送时间', prop: 'publish_time', minWidth: 170 },
    { label: '操作', align: 'center', render: 'actions', width: 220, fixed: 'right' }
  ];

  return useTable({
    type: LIST_TYPE.CONTENT,
    params: {
      type: 1,
      send_object: '',
      title: undefined
    },
    getParams: (params) => {
      return {
        ...params,
        ...formatParamsSelectVal([['send_object', '']], params)
      };
    },
    columns,
    getList
  });
};
